<!--Created by 王成 on 2018/7/4.-->
<div class="x_panel">
    <ul class="breadcrumb">
        <li><span class="primary-font"><i class="icon-home"></i></span><a href="index.html"> Home</a></li>
        <li>角色</li>
        <li>添加角色</li>
    </ul>
    <div class="smart-widget">
        <div class="smart-widget-header">
            添加列表
        </div>
        <div class="smart-widget-inner">
            <div class="smart-widget-body">
                <div class="row">
                    <div class="padding-md">
                        <form id="roleAddForm" method="post" class="form-horizontal  form-label-left" action="target.php">

                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="roleName">角色名称
                                </label>
                                <div class="col-lg-6">
                                    <input type="text" id="roleName" name="roleName" required="required"
                                           oninvalid="setCustomValidity('请输入角色名称');" class="form-control col-md-7 col-xs-12"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">角色描述</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                    <textarea id="middle-name" class="form-control col-md-7 col-xs-12" name="roleContent"
                              required="required" oninvalid="setCustomValidity('请输入角色描述');"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                    <button type="submit" onclick="save()" id="validateBtn" class="btn btn-primary">保存</button>
                                    <button class="btn btn-primary" onclick="reset()" id="resetBtn" type="button">重置</button>
                                    <button id="back" onclick="backToList()" class="btn btn-success" type="button">返回</button>
                                </div>
                            </div>

                        </form>
                    </div>
                </div><!-- ./row -->
            </div>
        </div><!-- ./smart-widget-inner -->
    </div><!-- ./smart-widget -->
</div>
<script>
    $(document).ready(function() {
        $('#roleAddForm').bootstrapValidator({
//        live: 'disabled',
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function (form) {
                $("#validateBtn").ajaxSubmit({
                    success: function (d) {
                        if (d == -1) {
                            alert("系统错误，请再试或联系系统管理员！");
                            return false;
                        } else {
//                            if ($.isEmptyObject($("#people_id").val())) {
//                                alert("新增成功！");
//
//                            } else {
//                                alert("修改成功！");
//                            }
                            $('#validateBtn').attr("disabled","disabled");
                            _query(1);
                        }
                    }
                });

            },
            fields: {  //startTimeToDate
                roleName: {
                    validators: {
                        notEmpty: {
                            message: '请输入角色名称'
                        }
                    }
                },
                roleContent: {
                    validators: {
                        notEmpty: {
                            message: '请输入角色描述'
                        }
                    }
                }

            }
        });

        // Validate the form manually
        $('#validateBtn').click(function() {
            $('form').bootstrapValidator('validate');

        });
        $('#resetBtn').click(function() {
            $('form').data('bootstrapValidator').resetForm(true);
        });
    });

    function backToList() {
        $.goTo('role/roleList.html')
    }
</script>

